package com.jushu.storbox.service;

import java.io.InputStream;
import java.util.List;
import java.util.Set;

import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.view.View;

import com.jushu.storbox.callback.ICallback;
import com.jushu.storbox.callback.IDownloadCallback;
import com.jushu.storbox.callback.IDownloadThumbnailCallback;
import com.jushu.storbox.callback.IShareDownloadCallback;
import com.jushu.storbox.callback.IUpdateStateChangeListener;
import com.jushu.storbox.callback.IUploadCallback;
import com.jushu.storbox.entities.FileFolderInfo;
import com.jushu.storbox.entities.FileInfo;
import com.jushu.storbox.entities.FolderInfo;
import com.jushu.storbox.entities.UploadObject;
import com.jushu.storbox.task.tqueue.DownloadTask;
import com.jushu.storbox.task.tqueue.ShareDownloadTask;
import com.jushu.storbox.task.tqueue.UploadTask;
import com.huawei.sharedrive.sdk.android.exception.ClientException;
import com.huawei.sharedrive.sdk.android.model.request.FolderCreateRequest;
import com.huawei.sharedrive.sdk.android.model.response.ADUser;
import com.huawei.sharedrive.sdk.android.modelV2.request.ClientInfoResponseV2;
import com.huawei.sharedrive.sdk.android.modelV2.request.FolderSearchRequestV2;
import com.huawei.sharedrive.sdk.android.modelV2.request.LinkCreateRequestV2;
import com.huawei.sharedrive.sdk.android.modelV2.response.FileInfoResponseV2;
import com.huawei.sharedrive.sdk.android.modelV2.response.FolderListResponseV2;
import com.huawei.sharedrive.sdk.android.modelV2.response.FolderResponse;
import com.huawei.sharedrive.sdk.android.modelV2.response.LinkInfoV2;
import com.huawei.sharedrive.sdk.android.modelV2.response.RefreshToken;
import com.huawei.sharedrive.sdk.android.modelV2.response.UserInfoV2;
import com.huawei.sharedrive.sdk.android.modelV2.response.UserResponseV2;
import com.huawei.sharedrive.sdk.android.modelV3.response.LinkInfoV3;
import com.huawei.sharedrive.sdk.android.service.handler.AsyncTaskHandler;

/**
 * 
 * IShareDriveService interface
 * 
 */
public interface ICloudDriveService
{
    public void settingServiceAdd();
    
    public UserResponseV2 login(String userName, String password) throws ClientException;
    
    public void updateFileSyncStatus(int isSync, FileFolderInfo info);
    
    public void updateFolderSyncStatus(int isSync, FileFolderInfo info);
    
    /**
     * @param folderID
     * @param des
     * @param limit
     * @param offset
     * @param orderby
     * @param authorization 
     * @return
     * @throws ClientException
     */
    public List<FileFolderInfo> getFileFolderList(String ownerId, String folderID, String des, int limit, int offset,
        String orderby) throws ClientException;
    
    public List<FileFolderInfo> getMoveFolderList(String ownerId, String folderID, String exception, int limit, int offset,
        String orderby) throws ClientException;
    
    public List<FileFolderInfo> getMoveFolderListDB(String ownerId, String folderID, String exception) throws ClientException;
    
    /**
     * @param folderID 
     * @param des
     * @param limit 
     * @param offset
     * @param orderby 
     * @param authorization
     * @return
     * @throws ClientException
     */
    public List<FileFolderInfo> getFileFolderListPage(String ownerId, String folderID, String des, String orderby)
        throws ClientException;
    
    
    /**
     * @param folderID 
     * @return
     * @throws ClientException
     */
    public List<FileFolderInfo> getFileFolderListPage(FileFolderInfo folder);
    
    /**
     * @param fileID 
     * @return
     */
    public String deleteAllFile(FileFolderInfo fileFolderInfo) throws ClientException;
    
    public void deleteAllFileAsync(Context context, final FileFolderInfo fileFolderInfomation, AsyncTaskHandler handler) throws ClientException;
    
    /**
     * @param fbr
     * @throws ClientException
     * @return 
     */
    public String deleteAllFolder(FileFolderInfo folder) throws ClientException;
    
    public void deleteAllFolderAync(final FileFolderInfo fileFolderInfomation, AsyncTaskHandler handler) throws ClientException;
    
    public FileFolderInfo createFolder(Context context, String ownerId, FolderCreateRequest request) throws ClientException;
    
    /**
     * @param fileID 
     * @param request 
     * @return 
     * @throws ClientException
     */
    public String moveFile(FileFolderInfo file, FileFolderInfo targetFolder)
        throws ClientException;
    
    /**
     * @param targetFolderId
     * @param fileFolderInfomation 
     * @return 
     * @throws ClientException
     */
    public FolderResponse moveFolder(FileFolderInfo fileFolderInfomation, FileFolderInfo targetFolder) throws ClientException;
    
    /**
     * search in cloud
     * 
     * @param context Context
     * @param limit int
     * @param offset int
     * @param name String
     * @return List<FileInformation>
     * @throws ClientException
     */
    public List<FileFolderInfo> searchInCloud(Context context, int limit, int offset, String name)
        throws ClientException;
    
    /**
     * 
     * @param folderID 
     * @param des
     * @param limit
     * @param offset
     * @param orderby（"name","size"）
     * @param authorization 
     * @param flag 
     * @return 
     * @throws ClientException
     */
    public List<FileFolderInfo> sortFileFolder(String ownerId, String folderID, String des, int limit, int offset,
        String orderby) throws ClientException;
    
    public String logout() throws ClientException;
    
    public FileFolderInfo renameFile(Context context, FileFolderInfo fileInformation, String name) throws ClientException;
    
    /**
     * 
     * @param fileInformation
     * @param newFolderName
     * @return
     * @throws ClientException
     */
    public FileFolderInfo renameFolder(FileFolderInfo fileInformation, String newFolderName) throws ClientException;
    
    /**
     * @param ownerID
     * @param folderID
     * @param authorization
     * @param fileDir
     * @param fileName
     * @param itemView
     */
    public void syncFolder(FileFolderInfo info, String fileName, String parentId, Handler handler, View itemView);
    
    /**
     */
    public FolderInfo selectFolder(FileFolderInfo fileFolderInfo);
    
    /**
     */
    public FileInfo selectFile(FileFolderInfo fileFolderInfo);
    
    /**
     * @param desc boolean
     * @param limite int
     * @param offset int
     * @param orderBy String
     * @return List<FileInformation>
     * @throws ClientException
     */
    public List<FileFolderInfo> getSharedFileFolder(boolean autoManualFlag, String folderId, String ownerId,
        String desc, int limite, int offset, String orderBy) throws ClientException;
    
    
    /**
     * @param folderID
     * @param des
     * @param limit 
     * @param offset
     * @param orderby
     * @param authorization 
     * @return 
     * @throws ClientException
     */
    public List<FileFolderInfo> getFileFolderListPage(boolean autoManualFlag, final Context context, String ownerId,
        String folderID, String des, String orderby, Handler handler) throws ClientException;
    
    public List<FileFolderInfo> getFileFolderListFromServer(final Context context, String ownerId, String folderID,
        String des, String orderby, Handler handler) throws ClientException;
    
    public List<FileFolderInfo> getFileFolderListFromDB(final Context context, String ownerId, String folderID, String des,
        String orderby, Handler handler) throws ClientException;
    
    /**
     * 
     * @param folderID 
     * @param des
     * @param limit 
     * @param offset
     * @param orderby 
     * @param authorization 
     * @return 
     * @throws ClientException
     */
    public List<FileFolderInfo> getSharedFileFolderListPage(boolean autoManualFlag, final Context context,
        String folderID, String des, String orderby, Handler handler, String SharedOwnerId)
        throws ClientException;
    
    public List<FileFolderInfo> getServerShareResourceList(Context context, String des, String folderId,
        String shareOwnerId, String orderBy) throws ClientException;
    
    public List<FileFolderInfo> getDBShareResourceList(String folderId, String ownerId, boolean desc,
        int limite, int offset, String orderBy);
    
    public List<FileFolderInfo> getBaseServerShareResourceList(String folderId, String ownerId, String desc,
        int limite, int offset, String orderBy) throws ClientException;
    
    public List<FileFolderInfo> getBaseDBShareResourceList(String folderId, String ownerId, String desc,
        int limite, int offset, String orderBy);
    
    /**
     * @param isSync
     */
    public void cancelSyncFolder(String ownerId, String folderId, String folderName);
    
    /**
     * @param isSync
     */
    public void cancelSyncFile(FileFolderInfo info, String fileName);
    
    /**
     * @see downloadFile
     * @param ownerID ownerID
     * @param folderID 
     * @param fileID 
     * @param authorization 
     * @param startIndex startIndex
     * @param filePath 
     * @param downloadCallback
     * 
     * @renturn 
     */
    public boolean downloadFile(String ownerID, String folderID, String fileID, String authorization,
        long fileSize, String filePath, IDownloadCallback downloadCallback,
        FileFolderInfo fileinfo);
    
    /**
     * @see downloadFile
     * @param ownerID ownerID
     * @param folderID
     * @param fileID
     * @param authorization 
     * @param startIndex startIndex
     * @param filePath 
     * @param downloadCallback 
     * 
     * @renturn
     */
    public DownloadTask openFile(String ownerID, String folderID, String fileID, String authorization,
        long fileSize, String filePath, ICallback downloadCallback,
        FileFolderInfo fileInformation);
    
    /**
     * @see downloadFile
     * @param downloadTask
     * @renturn 
     */
    public boolean downloadFile(DownloadTask downloadTask);
    
    /**
     * @see getAllDownloadTask
     * @return DownloadTask
     */
    public Set<DownloadTask> getAllDownloadTask();
    
    /**
     * @see getAllDownloadTask
     * @param folderID 
     * @return DownloadTask
     * @see / for(Iterator<UploadTask> itor = tasks.iterator(); itor.hasNext();) {
     *      UploadTask task = itor.next(); System.out.println("[" + tasks.size() + "]" +
     *      " id:" + task.getId() + " | priority:" + task.getPriority()); }
     * 
     * 
     */
    public Set<DownloadTask> getAllDownloadTask(String folderID);
    
    public DownloadTask getDownloadTask(String fileID);
    
    public boolean removeDownloadTask(String fileID);
    
    public int downloadTaskState(String fileID);
    public void downloadThumbnailIcon(String ownerBy, String fileId, String iconPath, IDownloadThumbnailCallback callback);
    
    
    public boolean downloadShareFile(String ownerID, String folderID, String fileID,
        long startIndex, long fileSize, String filePath, IShareDownloadCallback downloadCallback, FileFolderInfo fileFolderInfo, int isInode);
    
    public ShareDownloadTask openShareFile(String ownerID, String folderID, String fileID,
        long startIndex, long fileSize, String filePath, ICallback downloadCallback,
        FileFolderInfo fileFolderInfo,int isInode);
    
    public boolean downloadShareFile(ShareDownloadTask downloadTask);
    
    public Set<ShareDownloadTask> getAllDownloadShareTask();
    
    /**
     * @see getAllDownloadTask
     * @param folderID 
     * @return DownloadTask 
     * @see / for(Iterator<UploadTask> itor = tasks.iterator(); itor.hasNext();) {
     *      UploadTask task = itor.next(); System.out.println("[" + tasks.size() + "]" +
     *      " id:" + task.getId() + " | priority:" + task.getPriority()); }
     * 
     * 
     */
    public Set<ShareDownloadTask> getAllDownloadShareTask(String folderID);
    
    public ShareDownloadTask getDownloadShareTask(String fileID);
    
    public boolean removeDownloadShareTask(String fileID);
    public int downloadShareTaskState(String fileID);
    
    public void downloadShareThumbnailIcon(String ownerID, String iNodeID, String fileId, String iconPath,
        final IDownloadThumbnailCallback callback);
    
    /**
     * 
     * @param srcOwnerId
     * @param destFolderId
     * @param srcFileIdList
     * @param callback
     */
    public void shareFileSaveMyCloud(String targetOwnerId, final String srcOwnerId, final String destFolderId,
        final List<String> srcFileIdList, final IFileRemoteServiceCallback callback);

    public void shareFileSaveMyCloud(final String srcOwnerId, String destOwnerId, final String destFolderId,
        final String srcFileId, final IFileRemoteServiceCallback callback);
    
    public void uploadFile(String folderID, String filePath,
        IUploadCallback uploadCallback);
    
    public void uploadFile(String folderID,  String filePath,
        InputStream inputStream, IUploadCallback uploadCallback);

    public void uploadFile(String folderID, String filePath,
        String fileEncPath, InputStream inputStream, IUploadCallback uploadCallback);
    
    
    public void uploadFile(String folderID, List<String> filePaths,
        IUploadCallback uploadCallback, Handler uploadHandler);
    
   
    public void uploadFile(UploadTask uploadTask);


    public Set<UploadTask> getAllUploadTask();
    
    
    public Set<UploadTask> getAllUploadTask(String folderID);
    
   
    public UploadTask getUploadTask(String filePath);
    
    /**
     * @param fileList
     * @return
     * @throws ClientException
     */
    public boolean isServiceUpdate(Context context, FileFolderInfo info) throws ClientException;
    
    /**
     * 升级
     * @param onUpdateStateChangeListener
     * @param versionInfo
     * @param makeTxt
     * @return
     */
    public void upgradeCloudDrive(IUpdateStateChangeListener onUpdateStateChangeListener, ClientInfoResponseV2 versionInfo, boolean makeTxt);
    
    /**
     * @param trans_status
     * @param id
     */
    public void updateTransStatus(FileFolderInfo node, int trans_status);
    
    /**
     * @param id
     * @return
     */
    public FileInfo gainOnlyOne(String ownerId, String id);
    
    /**
     * @param id
     * @param localPath
     */
    public void updateLocalPath(String ownerId, String id, String localPath);
    
    /**
     * @param parentID
     * @return
     */
    public List<FolderInfo> selectParentIdAllFolder(String ownerId, String parentID);
    
    public void loginIn(String name, String passWord, Handler handler);
    
    /**
     * @param parentID
     * @return
     */
    public List<FileInfo> selectParentIdAllFile(String ownerId, String parentID);
    
    /**
     * @param autoManualFlag
     * @param context
     * @param folderID
     * @param des
     * @param limit
     * @param offset
     * @param orderby
     * @param shareOwnerId
     * @return
     * @throws ClientException
     */
    public List<FileFolderInfo> getSharedFileFolderList(boolean autoManualFlag, Context context,
        String folderID, String des, int limit, int offset, String orderby, String shareOwnerId)
        throws ClientException;
    
    /**
     * @param request
     * 
     * @return FolderResponse
     * @throws ClientException
     */
    public FolderListResponseV2 searchFolder(FolderSearchRequestV2 request) throws ClientException;
    
    /**
     * @param fileId
     */
    public FileFolderInfo selectShareINode(String fileId, String ownerId);
    
    /**
     * @param fileId
     */
    public FolderInfo selectShareFolder(String fileId, String ownerId);
    
    /**
     * @param fileId
     */
    public FileInfo selectShareFile(String fileId, String ownerId);
    
    /**
     * @param handler
     */
    public void clearCloudDriveCache(Handler handler);
    
    /**
     * @param handler 
     */
    public void getCloudDriveCache(Handler handler);
    
    public FileFolderInfo getDatabaseFolderByName(Context context, String ownerId, String folderName);
    
    /**
     * @return
     */
    public boolean checkIsRootAndNotify();
    
    void loginBackGround(Handler handler);
    
    public List<FileFolderInfo> searchInDB(String ownerId, String fileName, Context context);
    
    public long insertUploadData(FileInfoResponseV2 fileInfoResponse);
    
    void creatMobileForbiddenDialog();
    
    public boolean getResourceIsChange();
    
    public boolean getInodeResourceIsChange();
    
    public boolean getShareResourceIsChange();
    
    public void rejectShare(String authorization, long ownerId, long iNodeId) throws ClientException;
    
    public FileInfoResponseV2 copyFile(FileFolderInfo copyedFileFolderInfo,
    		FileFolderInfo targetFolder) throws ClientException;
    
    public FolderResponse copyFolder(FileFolderInfo savedFileFolderInfo, FileFolderInfo targetFolder) throws ClientException;
    
    /**
     * @param folderId
     * @return
     */
    public void deleteInodeFileOrFolder(String folderId, String ownerId);
    
    /**
     * @param keyText
     * */
    public List<ADUser> dbQueryMailList(String keyText);
    
    /**
     * @param mailList
     * */
    public void dbInsertMailList(List<ADUser> mailList) throws Exception;
    
    /**
     * @param keyText
     * */
    public List<UserInfoV2> svQueryMailList(String keyText) throws ClientException;
    
    /**
     * @param keyText 
     * */
    public List<UserInfoV2> queryMailList(String keyText) throws ClientException, Exception;
    
    public Dialog buildNowIsRootDialog();
    
    /**
     * @return
     */
    public List<FileInfo> getDownloadFileList();
    
    public List<UploadObject> getUploadFileList();
    
    public int readyMusic(Context context, FileFolderInfo path);
    
    public void playMusic();
    
    public void pauseMusic();
    
    public int getMusicProgress();
    
    public void setMusicProgress(int time);
    
    public boolean isMusicPlaying();
    
    public void destoryMusicplayer();
    
    /**
     * @param fileID
     */
    public void deleteDownloadFile(String fileID);
    
    /**
     * 
     * @param id
     * @param transStatus
     */
    public void updateDownloadState(String id, int transStatus);
    
    public String getServerAddress(String type) throws ClientException;
    
    public List<LinkInfoV3> getLink(FileFolderInfo fileInformation) throws ClientException;
    
    /**
     * @param authorization
     * @return
     * @throws ClientException
     */
    public boolean isComplexLinkCode(String authorization) throws ClientException;
    
    public LinkInfoV2 setLink(FileFolderInfo fileInformation) throws ClientException;
    
    /**
     * @param fileInformation
     * @throws ClientException
     */
    public void deleteLink(FileFolderInfo fileInformation) throws ClientException;
    
    /**
     * @param fileInformation
     * @param linkRequest
     * @return
     * @throws ClientException
     */
    public LinkInfoV2 updateLink(FileFolderInfo fileInformation,  LinkCreateRequestV2 linkRequest)
        throws ClientException;

	public boolean isServiceFileUpdate(Context context, FileFolderInfo info) throws ClientException;

	public RefreshToken refreshToken();
}
